package com.qfedu.yanglao20admin.equipment.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qfedu.yanglao20.common.CommonResult;
import com.qfedu.yanglao20.common.annotation.LogInfo;
import com.qfedu.yanglao20.entity.equipment.FacilityManage;
import com.qfedu.yanglao20admin.equipment.param.FacilityManageParam;
import com.qfedu.yanglao20admin.equipment.service.FacilityManageService;
import com.qfedu.yanglao20admin.equipment.vo.FacilityManageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author yujie
 * @data 2023/4/26 17:09
 */
@Api(tags = "设备管理")
@RestController
@RequestMapping("/equipment")
public class FacilityManageController {

    @Resource
    private FacilityManageService facilityManageService;

    @ApiOperation(value = "分页展示设备管理信息", notes = "分页展示设备管理信息")
    @GetMapping("/page")
    public CommonResult<FacilityManage> page(FacilityManageParam param) {
        Page<FacilityManageVO> facilityManageVOPage = facilityManageService.pageFacilityManage(param);
        return CommonResult.success(facilityManageVOPage);
    }


    @LogInfo
    @ApiOperation(value = "添加设备管理信息", notes = "添加设备管理信息")
    @PostMapping("/add")
    public CommonResult<FacilityManage> addFacilityManage(FacilityManage facilityManage) {
        facilityManageService.addFacilityManage(facilityManage);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "根据id查询设备管理信息", notes = "根据id查询设备管理信息")
    @GetMapping("/query")
    public CommonResult<FacilityManage> queryAFacilityManage(@RequestParam @ApiParam("设备管理信息id") Integer id) {
        FacilityManage facilityManage = facilityManageService.queryFacilityManage(id);
        return CommonResult.success(facilityManage);
    }

    @LogInfo
    @ApiOperation(value = "根据id删除设备管理信息", notes = "根据id删除设备管理信息")
    @GetMapping("/delete")
    public CommonResult<FacilityManage> deleteFacilityManage(@RequestParam @ApiParam("设备管理信息id") Integer id) {
        facilityManageService.deleteById(id);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "解除绑定状态", notes = "解除绑定状态")
    @GetMapping("/relieve")
    public CommonResult<FacilityManage> relieveFacilityManage(@RequestParam @ApiParam("设备管理信息id") Integer id) {
        facilityManageService.updatestateFlag(id);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "修改设备管理信息", notes = "修改设备管理信息")
    @PostMapping("/update")
    public CommonResult<FacilityManage> updateFacilityManage(FacilityManage facilityManage) {
        facilityManageService.updateFacilityManage(facilityManage);
        return CommonResult.success();
    }
}
